//
//  ZFBTabBarController.m
//  支付宝
//
//  Created by HaoYoson on 16/6/27.
//  Copyright © 2016年 HaoYoson. All rights reserved.
//

#import "UIColor+Addition.h"
#import "ZFBBusinessController.h"
#import "ZFBFriendController.h"
#import "ZFBHomeController.h"
#import "ZFBMineController.h"
#import "ZFBNavigationController.h"
#import "ZFBTabBarController.h"

@interface ZFBTabBarController ()

@end

@implementation ZFBTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self.tabBar setTintColor:[UIColor colorWithHex:0x00aaee]];

    NSMutableArray *vcs = [NSMutableArray array];

    [vcs addObject:[self loadChildViewControllerWithClassName:@"ZFBHomeController" andTitle:@"支付宝" andImageName:@"TabBar_HomeBar"]];

    [vcs addObject:[self loadChildViewControllerWithStoryboardName:@"ZFBBusiness" andTitle:@"口碑" andImageName:@"TabBar_Businesses"]];

    [vcs addObject:[self loadChildViewControllerWithClassName:@"ZFBFriendController" andTitle:@"朋友" andImageName:@"TabBar_Friends"]];

    [vcs addObject:[self loadChildViewControllerWithClassName:@"ZFBMineController" andTitle:@"我" andImageName:@"TabBar_Assets"]];

    self.viewControllers = vcs.copy;
}

- (UIViewController *)loadChildViewControllerWithStoryboardName:(NSString *)storyBoardName andTitle:(NSString *)title andImageName:(NSString *)imageName {
    // 获取sb对象
    UIStoryboard *sb = [UIStoryboard storyboardWithName:storyBoardName bundle:nil];
    // 获取剪头指向的控制器
    UIViewController *vc = [sb instantiateInitialViewController];

    return [self setupTabBarItemAndNavigationControllerWithRootViewController:vc andTitle:title andImageName:imageName];
}

- (UIViewController *)loadChildViewControllerWithClassName:(NSString *)className andTitle:(NSString *)title andImageName:(NSString *)imageName {
    Class Clz = NSClassFromString(className);
    UIViewController *vc = [[Clz alloc] init];

    return [self setupTabBarItemAndNavigationControllerWithRootViewController:vc andTitle:title andImageName:imageName];
}

- (UIViewController *)setupTabBarItemAndNavigationControllerWithRootViewController:(UIViewController *)viewController andTitle:(NSString *)title andImageName:(NSString *)imageName {
    viewController.tabBarItem.title = title;

    viewController.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    viewController.tabBarItem.selectedImage = [[UIImage imageNamed:[imageName stringByAppendingString:@"_Sel"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    ZFBNavigationController *nav = [[ZFBNavigationController alloc] initWithRootViewController:viewController];

    return nav;
}

@end
